using SKBKontur.Cassandra.Logging.Model;
using SKBKontur.Cassandra.Logging.Storage;
using SKBKontur.Logging.Model;

namespace SKBKontur.Cassandra.Logging.Model
{
    public class ConfigurationInfo : IConfigurationInfo
    {
        public string Keyspace { get; set; }
        public string MasterCf { get; set; }
        public string ExceptionCf { get; set; }
        public string InfoCf { get; set; }
        public string WarnCf { get; set; }
        public string DebugCf { get; set; }
        public string ErrorCf { get; set; }
        public string FatalCf { get; set; }
        public int ExceptionTtl { get; set; }
        public int InfoTtl { get; set; }
        public int WarnTtl { get; set; }
        public int DebugTtl { get; set; }
        public int ErrorTtl { get; set; }
        public int FatalTtl { get; set; }

        public ConfigurationInfo(string Keyspace, 
            string MasterCf, 
            string ExceptionCf, 
            string InfoCf, 
            string WarnCf, 
            string DebugCf, 
            string ErrorCf, 
            string FatalCf,
            int ExceptionTtl, 
            int InfoTtl, 
            int WarnTtl, 
            int DebugTtl, 
            int ErrorTtl, 
            int FatalTtl)
        {
            this.Keyspace = Keyspace;
            this.MasterCf = MasterCf;
            this.ExceptionCf = ExceptionCf;
            this.InfoCf = InfoCf;
            this.WarnCf = WarnCf;
            this.DebugCf = DebugCf;
            this.ErrorCf = ErrorCf;
            this.FatalCf = FatalCf;
            this.ExceptionTtl = ExceptionTtl;
            this.InfoTtl = InfoTtl;
            this.WarnTtl = WarnTtl;
            this.DebugTtl = DebugTtl;
            this.ErrorTtl = ErrorTtl;
            this.FatalTtl = FatalTtl;
        }

        private class SimpleCassandraLogParameters : ICassandraLogParameters
        {
            private IConfigurationInfo This;

            public SimpleCassandraLogParameters(IConfigurationInfo This, string EventCF, int EventTtl)
            {
                this.This = This;
                this.EventCF = EventCF;
                this.EventTtl = EventTtl;
            }

            public string EventCF { get; private set; }

            public string ExceptionCF
            {
                get { return This.ExceptionCf; }
            }

            public int EventTtl { get; private set; }

            public int ExceptionTtl
            {
                get { return This.ExceptionTtl; }
            }
        }

        public ICassandraLogParameters LogParameters(LogEventLevel level)
        {
            switch (level)
            {
                case LogEventLevel.Info:
                    return new SimpleCassandraLogParameters(this, InfoCf, InfoTtl);
                case LogEventLevel.Warn:
                    return new SimpleCassandraLogParameters(this, WarnCf, WarnTtl);
                case LogEventLevel.Debug:
                    return new SimpleCassandraLogParameters(this, DebugCf, DebugTtl);
                case LogEventLevel.Error:
                    return new SimpleCassandraLogParameters(this, ErrorCf, ErrorTtl);
                case LogEventLevel.Fatal:
                    return new SimpleCassandraLogParameters(this, FatalCf, FatalTtl);
                default:
                    return new SimpleCassandraLogParameters(this, InfoCf, InfoTtl);
            }
        }
    }
}